{% extends "base_generic.html" %}
{% block script %}
<script type="text/javascript">
  function generateUrl(name) {
    var sanitizedName = name;
    sanitizedName = sanitizedName.replace(/ el /gi, ' ');
    sanitizedName = sanitizedName.replace(/ la /gi, ' ');
    sanitizedName = sanitizedName.replace(/ los /gi, ' ');
    sanitizedName = sanitizedName.replace(/ las /gi, ' ');
    sanitizedName = sanitizedName.replace(/ de /gi, ' ');
    sanitizedName = sanitizedName.replace(/ del /gi, ' ');
    sanitizedName = sanitizedName.replace(/ temporada /gi, ' ');
    sanitizedName = sanitizedName.replace(/--/gi, '-');
    sanitizedName = sanitizedName.replace(/---/gi, '-');
    sanitizedName = sanitizedName.replace(/----/gi, '-');
    sanitizedName = string_to_slug(sanitizedName);
    $("#slug").val(sanitizedName);
  }
  function assignTagSlug(father) {
    {% for tag in tags %}
      if (father == "{{ tag.plural }}"){
        $("#tagSlug").val("{{ tag.pluralSlug }}");
      }
    {% endfor %}
    }
  function assignCategoriaSlug(father) {
    {% for categoria in categorias %}
      if (father == "{{ categoria.plural }}"){
        $("#categoriaSlug").val("{{ categoria.pluralSlug }}");
      }
    {% endfor %}
    }
</script>
{% endblock %}
{% block content %}
        <h1>Cosa</h1>
        <img src="/cosa/{% if slug %}{{ slug }}{% else %}{{ key }}{% endif %}/img" height="220" style="float:left; margin: 45px 20px 0 0" />
		<form action="/admin/cosas/{{ key }}/save/" method="post" style="float: left; width: 550px;">
        <div class="line">
          <div class="field">
            <label>Title:</label>
            <input id="title" name="title" type="text" size="65" value="{{ title }}" onblur="generateUrl(this.value);" />
          </div>
		</div>
		<div class="line">
          <div class="field">
            <label>Slug:</label>
            <input id="slug" name="slug" type="text" size="50" value="{{ slug }}" />
          </div>
        </div>
        <div class="line">
          <div class="field">
            <label>URL:</label>
            <input id="url" name="url" type="text" size="85" value="{{ url }}" />
          </div>
          <div class="field">
            <label>URL Image:</label>
            <input id="urlimg" name="urlimg" type="text" size="85" value="{{ urlimg }}" />
          </div>
        </div>
        <div class="line">
          <div class="field">
            <label>Categoría:</label>
            <select onchange="assignCategoriaSlug(this.value);" id="categoria" name="categoria">
              <option value=""></option>
              {% for acategoria in categorias %}
                <option value="{{ acategoria.plural }}"{% ifequal acategoria.plural categoria  %} selected="selected"{% endifequal %}>{{ acategoria.plural }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="field" style="display: none;">
            <label>Categoría Slug:</label>
            <input type="text" name="categoriaSlug" value="{{ categoriaSlug }}" id="categoriaSlug" size="20" />
          </div>
          <div class="field">
            <label>Tag:</label>
            <select onchange="assignTagSlug(this.value);" id="tag" name="tag">
              <option value=""></option>
              {% for atag in tags %}
                <option value="{{ atag.plural }}"{% ifequal atag.plural tag  %} selected="selected"{% endifequal %}>{{ atag.plural }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="field" style="display: none;">
            <label>Tag Slug:</label>
            <input type="text" name="tagSlug" value="{{ tagSlug }}" id="tagSlug" size="20" />
          </div>
        </div>
         <div class="line">
           <div class="field">
             <label>Description:</label>
             <textarea cols="85" rows="12" id="description" name="description">{% if description %}{{ description }}{% endif %}</textarea>
           </div>
        </div>
        <input type="hidden" name="codenum" id="codenum" value="{{ filekey }}" />
        <input type="submit" value="Guardar" id="save" name="save" name="save" /><br class="clear" />
      </form>
      <br class="clear" />

{% endblock %}
      